//
//  WPNextPwdViewController.m
//  ZhongChouPingTai
//
//  Created by WeiPan on 16/4/1.
//  Copyright © 2016年 HuaYiSoftware. All rights reserved.
//

#import "WPNextPwdViewController.h"

@interface WPNextPwdViewController ()
@property (nonatomic, strong) UITextField * pwdTextField;/**< 新密码输入框 */
@property (nonatomic, strong) UILabel * pwdIntroLabel;/**< 密码设置说明 */
@property (nonatomic, strong) UIButton * nextBtn;/**< 下一步按钮 */
- (void)initializeUserInterface; /**< 初始化用户界面 */


@end

@implementation WPNextPwdViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initializeUserInterface];
}
#pragma mark - init
- (void)initializeUserInterface {
    self.title = @"手机号码更改";
    [self.view addSubview:self.pwdTextField];
    [self.view addSubview:self.pwdIntroLabel];
    [self.view addSubview:self.nextBtn];
}
#pragma mark - responds events
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.view endEditing:YES];
}
- (void)respondsToNextBtn {
    [self.view endEditing:YES];
    if (_pwdTextField.text.length == 0) {
        [self initializeAlertControllerWithMessageAndDismiss:@"请输入新密码"];
        return;
    }
    for (UIViewController *temp in self.navigationController.viewControllers) {
        if ([temp isKindOfClass:[NSClassFromString(@"WPSafeViewController") class]]) {
            [self.navigationController popToViewController:temp animated:YES];
        }
    }
}
#pragma mark - 刷新数据
- (void)refreshData {
    
}
#pragma mark - getter
- (UITextField *)pwdTextField {
    if (!_pwdTextField) {
        _pwdTextField = ({
            UITextField * text = [[UITextField alloc]initWithFrame:CGRectMake(10*DHFlexibleHorizontalMutiplier(), navBar_Fheight+ 10*DHFlexibleHorizontalMutiplier(), 220*DHFlexibleHorizontalMutiplier(), 40*DHFlexibleHorizontalMutiplier())];
            text.leftViewMode = UITextFieldViewModeAlways;
            UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 60*DHFlexibleHorizontalMutiplier(), 35*DHFlexibleHorizontalMutiplier())];
            label.text = @"密码";
            label.font = [UIFont systemFontOfSize:13*DHFlexibleHorizontalMutiplier()];
            text.leftView = label;
            text.font = [UIFont systemFontOfSize:13*DHFlexibleHorizontalMutiplier()];
            text.clearButtonMode = UITextFieldViewModeWhileEditing;
            text.secureTextEntry = YES;
            text.placeholder = @"请输入您的新密码";
            text;
        });
    }
    return _pwdTextField;
}
- (UILabel *)pwdIntroLabel {
    if (!_pwdIntroLabel) {
        _pwdIntroLabel = ({
            UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(10*DHFlexibleHorizontalMutiplier(), CGRectGetMaxY(self.pwdTextField.frame), 310*DHFlexibleHorizontalMutiplier(), 30*DHFlexibleHorizontalMutiplier())];
            label.text = @"6-14位密码，建议数字，字母，符号组合";
            label.font = [UIFont systemFontOfSize:12*DHFlexibleHorizontalMutiplier()];
            label;
        });
    }
    return _pwdIntroLabel;
}

- (UIButton *)nextBtn {
    if (!_nextBtn) {
        _nextBtn = ({
            UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
            btn.frame = CGRectMake(10*DHFlexibleHorizontalMutiplier(), CGRectGetMaxY(self.pwdIntroLabel.frame) + 40*DHFlexibleHorizontalMutiplier(), 300*DHFlexibleHorizontalMutiplier(), 30*DHFlexibleHorizontalMutiplier());
            btn.backgroundColor = COLOR_RGB(234, 27, 47, 1);
            btn.layer.cornerRadius = 15*DHFlexibleHorizontalMutiplier();
            btn.titleLabel.font = [UIFont systemFontOfSize:13*DHFlexibleHorizontalMutiplier()];
            [btn setTitle:@"确定" forState:UIControlStateNormal];
            [btn addTarget:self action:@selector(respondsToNextBtn) forControlEvents:UIControlEventTouchUpInside];
            btn;
        });
    }
    return _nextBtn;
}
@end
